package com.levy.contronller.lamdaTest;

import java.util.Comparator;
import java.util.function.BinaryOperator;

public class BinaryOperatorTest {

    public static void main(String[] args) {
        BinaryOperatorTest binaryOperatorTest = new BinaryOperatorTest();
        System.out.println(binaryOperatorTest.operate(2, 3, (i1, i2) -> i1 + i2));

        System.out.println("---------------------------------");
        BinaryOperator.minBy((Comparator<Integer>) (o1, o2) -> o1 - o2).apply(1, 2);

        System.out.println("--------------------------------");
        String aShort = binaryOperatorTest.getShort("hello", "wolr", (o1, o2) -> o1.length() - o2.length());
        System.out.println(aShort);

        String a = binaryOperatorTest.getShort("hello", "wolr", (o1, o2) ->o1.charAt(0) - o2.charAt(0));
        System.out.println(a);

    }

    public Integer operate(Integer i1, Integer i2, BinaryOperator<Integer> binaryOperator) {
        Integer apply = binaryOperator.apply(i1, i2);
        return apply;
    }

    public String getShort(String s1, String s2, Comparator<String> comparator) {
        return BinaryOperator.minBy(comparator).apply(s1, s2);
    }
}
